#include <iostream>
#include <loki/Singleton.h>   // for Loki::SingletonHolder
#include "RandomClass.h"

#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>

using namespace Loki;  // okay for small programs
using namespace boost;

typedef SingletonHolder<CoreUtil::RandomClass, CreateUsingNew, PhoenixSingleton> RandomGenerator;

void hello()
{
	while(1)
	{
		std::cout << "Hello, Thread " << RandomGenerator::Instance().dice() << std::endl;;

		xtime xt;
		xtime_get(&xt, TIME_UTC);
		xt.nsec += 100;
		thread::sleep(xt);
	}
}

void hello2()
{
	while(1)
	{
		std::cout << "Hello, Thread2 " << RandomGenerator::Instance().dice() << std::endl;;

		xtime xt;
		xtime_get(&xt, TIME_UTC);
		xt.nsec += 100;
		thread::sleep(xt);
	}
}

int main(int argc, char* argv[])
{
	thread t(&hello);
	thread t2(&hello2);
	t.join();
	t2.join();
    
#if defined(__BORLANDC__) || defined(_MSC_VER)
    system("PAUSE");
#endif

    return 0;
}

